package edu.cuit.avatar;

import java.util.Scanner;

public class Hex2Dec {
    public static void main(String[] args) {
        System.out.println("请输入一个16进制系统的数值:");
        try(Scanner input = new Scanner(System.in)){
            String number = input.nextLine().trim();

            if(number.length() != 1){
                System.err.println("非法的数值:" + number);
                return;
            }

            if('0' <= number.charAt(0) && '9' >= number.charAt(0)){
                int digit = Integer.parseInt(number);
                System.out.println(digit);
            } else if('A' <= number.charAt(0) && 'F' >= number.charAt(0)){
                //int digit = Integer.parseInt(number,16);
                int digit = number.charAt(0) - 'A' + 10;
                System.out.println(digit);
            } else{
                System.out.println("非法的数值");
            }
        }
    }
}
